package com.fastjars.shiro.realm;

import com.fastjars.shiro.model.User;
import com.fastjars.shiro.utils.PwdUtil;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.util.ByteSource;

/**
 * WechatOrSmsCodeRealm
 * 微信登录/短信验证码登录
 * @author Brant Liu <br> 邮箱：<br>lbf1988@qq.com <br>日期：<br>2018/10/11
 * @version 1.0.0
 */
public class WechatOrSmsCodeRealm extends AbstractRealm {
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        User token = validatePrincipal(authenticationToken);
        return new SimpleAuthenticationInfo(token, PwdUtil.getPwdToHex(token.getEncryptKey(), String.valueOf(authenticationToken.getPrincipal()),token.getSalt()), ByteSource.Util.bytes(token.getEncryptKey()+token.getSalt()), getName());
    }
}
